<?php

namespace App\Console\Commands\Shop;

use App\Kuafu\Banner\Enum\BannerEnum;
use App\Kuafu\Banner\Model\BannerCommonModel;
use App\Kuafu\Common\Service\CommonService;
use Illuminate\Console\Command;

class InitBannerImgs extends Command
{
    protected $signature = 'initBannerImgs';

    protected $description = '初始化banner图片配置多图json数据';


    public function handle()
    {

        BannerCommonModel::query()
                         ->whereIn("type", array_keys(BannerEnum::TYPE_TV_GROUP))
                         ->chunkById(100, function ($bannerCommonModel) {
                             foreach ($bannerCommonModel as $banner) {
                                 if ($banner->img) {
                                     $banner->imgs = [CommonService::joinImageUrl($banner->img)];
                                     $banner->save();
                                 }
                             }
                         });
    }

}
